const Admin = require("../model/Admin")
const md5 = require('md5')

exports.addAdmin = function(loginId,Paw,name){
    const loginPaw = md5(Paw);
    Admin.create({
        loginId,
        loginPaw,
        name
    }).then(()=>{
        console.log("Admin add ok");
    })
}
exports.login= async function(loginId,paw){
    // const loginPaw = md5(paw);
    const result = await Admin.findOne({
        attributes:["id"],
        where:{
            loginId,
            loginPaw:paw
        }
    })

    return result;
}

exports.getAdmin = async function(id){

    console.log(id);

   const result  = await Admin.findByPk(id);

   if(result.id){
       return true;
   }else{
       return false;
   }
   
}

exports.findAdmin =function (){
    Admin.findAll().then((e)=>{
        console.log(JSON.stringify(e,null,2));
    })
}
